package com.yanqu.road.server.cmd.children;

import com.yanqu.road.pb.child.ChildProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.ChildModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_CHILD_SITE_TRAIN_TIMES_RECOVER, desc = "恢复培养次数")
public class ChildSiteTrainTimesRecoverCmd extends AbstractCommand {

    private int siteIndex;

    private int useCount;

    private int goodsId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ChildProto.ChildSiteTrainTimesRecoverReqMsg reqMsg = ChildProto.ChildSiteTrainTimesRecoverReqMsg.parseFrom(packet.getBytes());
        siteIndex = reqMsg.getSiteIndex();
        goodsId = reqMsg.getGoodsId();
        useCount = reqMsg.getUseCount();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(ChildModule.class).childSiteTrainTimesRecover(siteIndex, goodsId, useCount);
    }

    @Override
    public void sendData(GamePlayer player) {
        ChildProto.ChildSiteTrainTimesRecoverRespMsg.Builder respMsg = ChildProto.ChildSiteTrainTimesRecoverRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_CHILD_SITE_TRAIN_TIMES_RECOVER, respMsg);
    }
}
